#-*- coding:utf-8 –*-

import FP_Grow_tree
import pandas as pd
sample=[
	['milk','eggs','bread','chips'],
	['eggs','popcorn','chips','beer'],
	['eggs','bread','chips'],
	['milk','eggs','bread','popcorn','chips','beer'],
	['milk','bread','beer'],
	['eggs','bread','beer'],
	['milk','bread','chips'],
	['milk','eggs','bread','butter','chips'],
	['milk','eggs','butter','chips']
]
sample1=[
	[u'牛奶',u'鸡蛋',u'面包',u'薯片'],
	[u'鸡蛋',u'爆米花',u'薯片',u'啤酒'],
	[u'鸡蛋',u'面包',u'薯片'],
	[u'牛奶',u'鸡蛋',u'面包',u'爆米花',u'薯片',u'啤酒'],
	[u'牛奶',u'面包',u'啤酒'],
	[u'鸡蛋',u'面包',u'啤酒'],
	[u'牛奶',u'面包',u'薯片'],
	[u'牛奶',u'鸡蛋',u'面包',u'黄油',u'薯片'],
	[u'牛奶',u'鸡蛋',u'黄油',u'薯片']
]
sample2=[
    ["A","B","C","D"],
    ["A","C"],
    ["D"],
    ["B","C","D"],
    ["A","C","D"],
    ["A","B","D"],
    ["C","D"],
    ["E"],
    ["A","D","E"]]

def testFPtree():
    pFile = "E:/csdn/chaoshi.xls"
    dframe = pd.read_excel(pFile)
    headLst = dframe.columns.values.tolist()
    print(headLst)
    # print(headLst[3])
    arr = dframe.values
    # print(dframe.shape[0])
    # print(len(arr), arr[0])
    # print(list(arr[7]))
    dataLst = []
    cols = len(headLst)
    for row in range(dframe.shape[0]):
        rowLst = []
        for col in range(cols):
            if arr[row][col] == 'T':
                rowLst.append(headLst[col])
        dataLst.append(rowLst)
    return dataLst

if __name__ == '__main__':
	#print(sample1)
	##参数说明 sample为事务数据集 []为递归过程中的基,support为最小支持度
	support=100
	dataLst = testFPtree()

	ff=FP_Grow_tree.FP_Grow_tree(dataLst,[],support)
	##打印频繁集
	ff.printfrequent()
